package com.sxt.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 雷哥
 * @Date: 2020/10/07/23:27
 * @Description:
 */
@Configuration
public class RoutingTopicConfig {

  /**
   * 声明交换机
   */
  @Bean
  public TopicExchange topicExchange(){
    TopicExchange topicExchange=new TopicExchange("topics");
    return topicExchange;
  }

  /**
   * 声明队列1
   */
  @Bean
  public Queue topicQueue1(){
    return new Queue("topicQueue1");
  }

  /**
   * 声明队列2
   */
  @Bean
  public Queue topicQueue2(){
    return new Queue("topicQueue2");
  }

  /**
   * 把队列1绑定到交换机里面并指定队列的路由key为user.*
   */
  @Bean
  public Binding binding111(){
    Binding binding= BindingBuilder.bind(topicQueue1())
        .to(topicExchange()).with("user.*");
    return binding;
  }
  /**
   * 把队列2绑定到交换机里面并指定队列的路由key为user.#
   */
  @Bean
  public Binding binding222(){
    Binding binding= BindingBuilder.bind(topicQueue2())
        .to(topicExchange()).with("user.#");
    return binding;
  }

}
